package com.heima.article.controller;
// 爱情不是随便许诺,算了,不想再说了

import com.heima.article.service.ApArticleService;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.media.dtos.WmNewsDto;
import com.heima.model.media.dtos.WmNewsResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ArticleController {

    @Autowired
    private ApArticleService apArticleService;

    /**
     * 保存文章
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/article/save")
    public Long saveArticle(@RequestBody WmNewsResultDTO dto) {
        return apArticleService.saveArticle(dto);
    }






    /**
     * 加载首页
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/article/load")
    public ResponseResult<List<ArticleDto>> load(@RequestBody ArticleHomeDto dto) {
        return ResponseResult.ok(apArticleService.load(dto, 1));
    }

    /**
     * 上拉
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/article/loadmore")
    public ResponseResult<List<ArticleDto>> loadMore(@RequestBody ArticleHomeDto dto) {
        return ResponseResult.ok(apArticleService.load(dto, 1));
    }


    /**
     * 下拉
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/article/loadnew")
    public ResponseResult<List<ArticleDto>> loadNew(@RequestBody ArticleHomeDto dto) {
        return ResponseResult.ok(apArticleService.load(dto, 2));
    }


    /**
     * 分页查询文章数据
     *
     * @param size
     * @param page
     * @return
     */
    @GetMapping("/api/v1/article/findByPage")
    public List<ArticleDto> findByPage(@RequestParam("size") Integer size,
                                       @RequestParam("page") Integer page) {
        return apArticleService.findByPage(page, size);
    }


    /**
     * 根据id 查询自媒体文章
     * @param id
     * @return
     */
    @GetMapping("/api/v1/news/one/{id}")
    public ArticleDto selectOneArticle(@PathVariable("id") Integer id){
      return apArticleService.selectOneArticle(id);
    }


    /**
     * 删除自媒体文章
     * @param id
     * @return
     */
    @DeleteMapping("/api/v1/news/del_news/{id}")
    public void deleteByIdArticle(@PathVariable("id") Integer id){
        apArticleService.deleteByIdArticle(id);
    }


    /**
     * 审核通过
     *
     * @param
     * @return
     */
    @PostMapping("/api/v1/news_auth/auth_pass")
    public void saveById(@RequestBody WmNewsResultDTO dto){
        apArticleService.saveByWmNewsDto(dto);
    }
}
